.PHONY: help build run stop restart logs clean test health

# 默认目标
help:
	@echo "Wan2.1-T2V-14B - 文生视频推理部署（8卡NPU）"
	@echo ""
	@echo "可用命令:"
	@echo "  make build    - 构建Docker镜像"
	@echo "  make run      - 启动服务"
	@echo "  make stop     - 停止服务"
	@echo "  make restart  - 重启服务"
	@echo "  make logs     - 查看日志"
	@echo "  make health   - 健康检查"
	@echo "  make test     - 运行API测试"
	@echo "  make clean    - 清理容器和镜像"
	@echo "  make npu      - 检查NPU状态"

# 构建Docker镜像
build:
	@echo "构建Docker镜像..."
	docker build -t wan2.1-t2v-14b:latest .

# 使用docker-compose启动服务
run:
	@echo "启动Wan2.1-T2V API服务..."
	docker-compose up -d

# 停止服务
stop:
	@echo "停止服务..."
	docker-compose down

# 重启服务
restart:
	@echo "重启服务..."
	docker-compose restart

# 查看日志
logs:
	docker-compose logs -f

# 健康检查
health:
	@echo "执行健康检查..."
	@curl -s http://localhost:8000/health | python3 -m json.tool || echo "服务未运行或不可访问"

# 检查NPU状态
npu:
	@echo "检查NPU状态..."
	@npu-smi info || echo "无法访问NPU设备"

# 运行测试
test:
	@echo "运行API测试..."
	@chmod +x test_api.sh
	@./test_api.sh

# 清理
clean:
	@echo "清理容器和镜像..."
	docker-compose down -v
	docker rmi wan2.1-t2v-14b:latest 2>/dev/null || true
	@echo "清理输出文件..."
	rm -rf outputs/* temp/* logs/*

# 直接运行（非Docker，用于开发）
dev:
	@echo "警告: 开发模式需要在NPU环境中运行"
	@echo "启动开发模式..."
	python3 -m uvicorn api.main:app --reload --host 0.0.0.0 --port 8000

# 查看任务输出目录
outputs:
	@echo "输出目录内容:"
	@ls -lh outputs/

# 进入容器shell
shell:
	@docker exec -it wan2.1-t2v-14b-api /bin/bash
